clear
macro drop _all 
set more off

* specify where regression sample is saved
global direc_sample "..."

* specify where regression estimates will be saved
global direc_estimates "..."

* specify where regression output figures will be saved
global direc_output "..."

* window size around the year when the regulation is introduced
global wsize = 2

* import data
import delimited "${direc_sample}/regression_sample.csv", clear

* define treatment var
do _create-treatment-var "state_id"

* labels
run _labels

*** sample restrictions
qui su year
global If "if inrange(reg_year, `r(min)' + $wsize, `r(max)' - $wsize)"
keep $If

*** regression analysis
global DepVars "plans_making_nonzero_new_sales insurers_making_nonzero_new_sale avg_prems_new_sale m_insurers_making_nonzero_new_sa f_insurers_making_nonzero_new_sa avg_prems_new_sale_od_1st_issue"

foreach depvar of varlist $DepVars {
	
	reghdfe `depvar' ib`=$wsize'.year_post_reg i.year, a(state_id) cluster(state_id)
	est save "${direc_estimates}/`depvar'-dynamic", replace
	
	sum `depvar' if e(sample)
}

*** regression output figures
run _plot_coeff "${DepVars}" "state"










